﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using COFE.Core.Entry;

namespace COFE.Core.Logger
{
    public class EventLogPropertyProvider : IPropertyProvider        
    {
        #region Constructor

        public EventLogPropertyProvider(Int64 id, DateTime time, string sender,
            string userId, EventArgs eventArgs)
        {
            _id = id;
            _time = time;
            _sender = sender;
            _userId = userId;
            _eventArgs = eventArgs;
        }

        #endregion

        #region Methods

        public IEnumerable<object> GetSupportedProperty()
        {
            //foreach (var prop in Enum.GetValues(typeof(EventLogProperties)))
            //    yield return prop;
            yield return EventLogProperties.Id;
            yield return EventLogProperties.Time;
            yield return EventLogProperties.Sender;
            yield return EventLogProperties.UserId;
            yield return EventLogProperties.Message;
            yield return EventLogProperties.Event;

        }

        public PropertySupportOptions GetPropertySupportOptions(object property)
        {
            if (GetSupportedProperty().Contains(property))
                return PropertySupportOptions.CanRead;
            return PropertySupportOptions.None;
        }

        public PropertyPair GetProperty(object property)
        {
            switch ((int)property)
            {
                case (int)EventLogProperties.Id :
                    return new PropertyPair(property, _id);
                case (int)EventLogProperties.Time :
                    return new PropertyPair(property, _time);
                case (int)EventLogProperties.Sender:
                    return new PropertyPair(property, _sender);
                case (int)EventLogProperties.UserId:
                    return new PropertyPair(property, _userId);
                case (int)EventLogProperties.Message:
                    return new PropertyPair(property, _eventArgs.ToString());
                case (int)EventLogProperties.Event:
                    return new PropertyPair(property, _eventArgs);

            }
            throw new NotSupportedException(property.ToString());
        }

        public void SetProperty(object property, object value)
        {
            throw new NotSupportedException();
        }

        public void Refresh()
        {
            
        }

        #endregion

        #region Data

        public Int64 _id;
        public DateTime _time;
        public string _sender;
        public string _userId;
        public EventArgs _eventArgs;


        #endregion

        #region Public Properties

        
        #endregion
       
    }

}
